﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script src="../../Scripts/common/jquery.leanModal.min.js" type="text/javascript"></script>
        <style type="text/css">
        #lean_overlay { position: fixed; z-index: 100; top: 0px; left: 0px; height: 100%; width: 100%; background: #000; display: none; }
        #OpenWindow { font-size:12px; background: none repeat scroll 0 0 #FFFFFF; border-radius: 5px 5px 5px 5px; box-shadow: 0 0 4px rgba(0, 0, 0, 0.7); display: none; padding-bottom: 2px; width: 300px; z-index: 11000; left: 50%; margin-left: -202px; opacity: 1; position: fixed; top: 200px;}
        #OpenWindow-header { background: url("../../img/hd-bg.png") repeat scroll 0 0 transparent; border-bottom: 1px solid #cccccc; border-top-left-radius: 5px; border-top-right-radius: 5px; padding: 10px; }
        #OpenWindow-header h2{margin-left:10px;}
        .modal_close { background: url("../../img/modal_close.png") repeat scroll 0 0 transparent; display: block; height: 14px; position: absolute; right: 12px; top: 12px; width: 14px; z-index: 2; }
 
        #OpenWindow .txt-fld { border-bottom: 1px solid #EEEEEE; padding: 8px 6px; position: relative; text-align: left; width: 244px;cursor:pointer;}
        #OpenWindow .txt-fld label { padding-left: 15px;color:Black;}
        </style>

<script type="text/javascript" language="JavaScript">
    //var LibraryBookIndent = { lbi_id: 0, lbi_uid: 0, lbi_lbid: 0, lbi_state: 0, lbi_time: new Date(), lbi_ip: "", lbi_ucid: 0 };
    var mylist, lbistate = [];
    var regular_input = {
        lbi_uid: { exp: /^[0-9]\d*$/, m: "请选择会员" },
        lbi_lbid: { exp: /^[0-9]\d*$/, m: "请选择图书" }
    }
    var mainForm = "";
    $(document).ready(function () {
        $(".txt-fld").mousemove(function (o) {
            $(this).css("background-color", "#cccccc");
        });
        $(".txt-fld").mouseout(function (o) {
            $(this).css("background-color", "#ffffff");
        });
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };
        function ajax() {
            var bookName = $.trim($("#seekForm :input[name=txtbookName]").val());
            var userName = $.trim($("#seekForm :input[name=txtUserName]").val());
            var state = $.trim($("#seekForm :input[name=selstate]").val());
            var card = $.trim($("#seekForm :input[name=txtId]").val());
            var isbn = $.trim($("#seekForm :input[name=txtIsbn]").val());
            var indent = $.trim($("#seekForm :input[name=txtIndent]").val());
            var time_s = $.trim($("#seekForm :input[name=txttime_s]").val());
            var time_e = $.trim($("#seekForm :input[name=txttime_e]").val());
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage, bookName: bookName, name: userName,
                state: state, card: card, isbn: isbn, indent: indent, in_s: time_s, in_e: time_e
            };
            $.post("/LibraryBook/getLibraryBookIndent.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            var mapid;
            $("#mainTable tbody[name=mainlist]").html("");
            var lbiid = 0;

            $.each(list, function (i, n) {
                if (n.lbi_id != lbiid) {
                    $.ajax({
                        type: "POST",
                        url: "/LibraryBook/getLibraryBookName.html",
                        data: "indentid=" + n.lbi_id,
                        async: false,
                        success: function (msg) {
                            sp.push('<tr>');
                            sp.push('<td>' + n.u_name + '</td>');
                            sp.push('<td>' + msg + '</td>');
                            sp.push('<td>' + n.lbi_time.Format("yyyy-MM-dd hh:mm") + '</td>');
                            sp.push('<td>' + lbistate["x" + n.lbi_state] + '</td>');
                            var IndentJson = $.toJSON(n);
                            sp.push((n.lbi_state == 3 || n.lbi_state == -1) ? "<td></td>" : "<td><a href=\'#OpenWindow\' onclick='javascript:detail(" + IndentJson + ")'  rel=\'leanModal\'  name=\'linkEdit\'>处理订单</a></td>");
                            sp.push('</tr>');
                        }
                    });
                }
                lbiid = n.lbi_id;
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
            $('a[rel*=leanModal]').leanModal({ top: 100, closeButton: ".modal_close" });
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        ajax();
        $("input[name=buttsend]").click(function () {
            var id = $("#hidIndentId").val();
            var oldState = $("#hidOldState").val();
            var state = $("#updatestate").val();
            $.post("/LibraryBook/updateIndentState.html", { id: id, oldState: oldState, state: state }, function (dta) {
                if (dta == "succe") {
                    alert("订单处理成功");
                    window.parent.frames["rightFrame"].location.reload();
                    ajax();
                } else {
                    alert("订单处理失败");
                    window.parent.frames["rightFrame"].location.reload();
                    ajax();
                }
            });
        });

        $("input[name=buttEdit1]").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            //$.fillObj(LibraryBookIndent, "#mainForm");
            if ($("#bname").val() == "") {
                alert("请选择图书");
                $("#bname").focus();
                return false;
            } //LibraryBookIndent: $.toJSON(LibraryBookIndent), 
            $.post("/LibraryBook/saveLibraryBookIndent.html", { lbiuid: $("#lbi_uid").val(), lbid: $("#hidBid").val(), bookname: $("#bname").val() }, function (dta) {
                if (dta == "succe") {
                    alert("借书成功");
                    window.parent.frames["rightFrame"].location.reload();
                    ajax();
                }
                else if (dta == "notimes") {
                    alert("借书失败，充值卡无剩余次数");
                }
                else if (dta == "erroruserrule") {
                    alert("借书失败，临时会员无法借书");
                }
                else if (dta == "erroruser") {
                    alert("借书失败，会员信息异常");
                }
                else if (dta == "best4") {
                    alert("借书失败，该会员借书量已达4本");
                }
                else if (dta == "nocard") {
                    alert("借书失败，该会员无充值卡");
                }
                else if (dta == "bbcz") {
                    alert("借书失败，图书不存在");
                }
                else if (dta == "bnkc") {
                    alert("借书失败，库存不足");
                }
                else if (dta == "bxj") {
                    alert("借书失败，图书已下架");
                }
                else if (dta == "bdzs") {
                    alert("借书失败，电子书不能进入借书流程");
                }
                else {
                    alert("借书失败，图书" + dta + "数据异常");
                }
            });
        });

    });
    function detail(n) {
        $("#hidIndentId").val(n.lbi_id);
        $("#hidOldState").val(n.lbi_state);
        $("#updatestate").val(n.lbi_state);
    }

    //查询会员
    function seekUser() {
        var obj = $(":text[name=_txt_name]")[0], name;
        var obj1 = $(":text[name=_txt_nick]")[0], nick;
        var obj5 = $(":text[name=_txt_card]")[0], card;
        if (obj)
            name = $.trim(obj.value);
        if (obj1)
            nick = $.trim(obj1.value);
        if (obj5)
            card = $.trim(obj5.value);
        var sb = [];

        sb.push('亲，输入条件查询后,请双击选择会员~');
        sb.push('<table style="width:350px;cursor:hand;" cellspacing="0">');
        sb.push('<th>');
        sb.push('姓名：<input type="text" style="width:50px"  name="_txt_name"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('登录名:<input type="text" style="width:50px"  name="_txt_nick"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('卡号:<input type="text" style="width:50px"  name="_txt_card"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('<a href="javascript:void(0);" onclick="seekUser()">查 询</a>');
        sb.push('</th>');

        $.post("/LibraryBook/getUserInfoByCard.html", { name: name, nick: nick, card: card }, function (dta) {
            $.each($.evalJSON(dta), function (i, o) {
                sb.push("<tr ondblclick='selectUser(" + o.u_id + ",\"" + o.u_name + "\")'><td colspan='2'>" + o.u_nick + "</td><td colspan='2'>" + o.u_name + "</td></tr>");
            });
            sb.push('</table>');
            popLayer.show("", sb.join(''), " ", false, "");
        });

    }

    function selectUser(id, name) {
        $("#mainForm :input[name=lbi_uid]").val(id);
        $("#uname").val(name);
        popLayer.close();
    }

    //查询图书
    function seekBook() {
        var obj3 = $(":text[name=_txt_bname]")[0], name;
        var obj4 = $(":text[name=_txt_author]")[0], author;
        var obj6 = $(":text[name=_txt_isbn]")[0], isbn;
        if (obj3)
            name = $.trim(obj3.value);
        if (obj4)
            author = $.trim(obj4.value);
        if (obj4)
            isbn = $.trim(obj6.value);
        var sb = [];

        sb.push('亲，输入条件查询后,请双击选择图书~');
        sb.push('<table style="width:360px;cursor:hand;" cellspacing="0">');
        sb.push('<th>');
        sb.push('书名：<input type="text" style="width:60px"  name="_txt_bname"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('作者:<input type="text" style="width:60px"  name="_txt_author"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('ISBN:<input type="text" style="width:60px"  name="_txt_isbn"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('<a href="javascript:void(0);" onclick="seekBook()">查 询</a>');
        sb.push('</th>');

        $.post("/LibraryBook/getBooklist.html", { name: name, author: author, isbn: isbn }, function (dta) {
            $.each($.evalJSON(dta), function (i, o) {
                sb.push("<tr ondblclick='selectBook(" + o.lb_id + ",\"" + o.lb_bookName + "\")'><td colspan='2'>" + o.lb_bookName + "</td><td>" + o.lb_author + "</td><td>" + o.lbd_isbn + "</td></tr>");
            });
            sb.push('</table>');
            popLayer.show("", sb.join(''), " ", false, "");
        });
    }

    function selectBook(id, name) {
        if ($("#bname").val() == "") {
            $("#bname").val($("#bname").val() + name);
        } else {
            $("#bname").val($("#bname").val() + "," + name);
        }
        //
        if ($("#hidBid").val() == "") {
            $("#hidBid").val($("#hidBid").val() + id);
        } else {
            $("#hidBid").val($("#hidBid").val() + "," + id);
        }
        popLayer.close();
    }

</script>
<div id="OpenWindow">
        <div id="signup-ct">
            <div id="OpenWindow-header">
                <h2 id="sutitle">处理订单</h2>
                <a href="#" class="modal_close"></a>
            </div>
            <div class="txt-fld">
              请选择订单状态：<select id="updatestate" name="updatestate">
                    <%
                        foreach (string s in Enum.GetNames(typeof(DAL.Enums.lbistate)))
                        {
                            int _v = (int)Enum.Parse(typeof(DAL.Enums.lbistate), s);
                            Response.Write("<option value='" + _v + "'>" + s + "</option>");
                        }
                    %>
                </select>
            </div>
            <div  class="txt-fld">
            <input type="hidden" id="hidIndentId" name="hidIndentId" />
            <input type="hidden" id="hidOldState" name="hidOldState" />
                <input  type="button" name="buttsend" id="buttsend" class="btn1"  value="确认" />
            </div>
            <div style="height:20px;"></div>
        </div>
    </div>
<table cellspacing="0" id="seekForm">
        <tr>
            <th>
                订单管理
            </th>
        </tr>
        <tr>
        <td >
            卡号：<input type="text" name="txtId" />
            ISBN：<input type="text" name="txtIsbn" /> 
            订单号：<input type="text" name="txtIndent" />
            学员姓名：<input type="text" name="txtUserName" />    
            书名：<input type="text" name="txtbookName" /> 
            </p>
            订单状态：<select name="selstate">
                    <option value="-2">请选择</option>
                    <%
                        foreach (string s in Enum.GetNames(typeof(DAL.Enums.lbistate)))
                        {
                            int _v = (int)Enum.Parse(typeof(DAL.Enums.lbistate), s);
                            Response.Write("<option value='" + _v + "'>" + s + "</option>");
                            Response.Write("<script>lbistate['x" + _v + "']='" + s + "';</script>");
                        }
                    %>
                </select>
                下单日期：<input type="text" size="15" name="txttime_s" value="<%=System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd") %>" class="date" />
                至<input type="text" size="15" name="txttime_e" value="<%=System.DateTime.Now.ToString("yyyy-MM-dd") %>" class="date" />
            <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
    </table>
<table id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">订单列表</caption>
        <tr>
            <th>学员姓名</th>
            <th>书名</th>
            <th>下单时间</th>
            <th>订单状态</th>
            <th></th>
            </tr>
        <tbody name="mainlist">        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>

    <table cellspacing="0" id="mainForm">
        <caption>
            编辑订单</caption>
        <tr>
            <th colspan="3">
                编辑订单
            </th>
        </tr>
         <tr>
            <td>会员*</td>
            <td>
            <input type="hidden" id="lbi_uid" name="lbi_uid"/>
            <input type="text" readonly="readonly" id="uname"/>
            <a href="javascript:void(0);" onclick="seekUser()" style="cursor:hand;" >点此选择会员</a>
            </td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>图书*</td>
            <td>
            <textarea rows="2" readonly="readonly" id="bname"></textarea>
            <input type="hidden" id="hidBid" name="hidBid" />
            <a href="javascript:void(0);" onclick="seekBook()" style="cursor:hand;" >点此选择图书</a>
            </td>
            <td><span class="tsxx"></span></td>
        </tr>
<%--        <tr>
            <td>订单状态*</td>
            <td>
            <select name="lbi_state">
                    <%
                        foreach (string s in Enum.GetNames(typeof(DAL.Enums.lbistate)))
                        {
                            int _v = (int)Enum.Parse(typeof(DAL.Enums.lbistate), s);
                            Response.Write("<option value='" + _v + "'>" + s + "</option>");
                        }
                    %>
                </select>
            </td>
            <td><span class="tsxx"></span></td>
        </tr>--%>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttEdit1" class="btn1" style="width: 200px" value="新增" />
 
            </td>
        </tr>
    </table>

</asp:Content>
